// 2. 有状态组件
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  // 请求一般在 initState 生命周期函数
  @override
  void initState() {
    getData();
    super.initState();
  }

  getData() async {
    Dio http = Dio();
    Response res = await http.get('https://mock.boxuegu.com/mock/1172/orders');
    // res.data 是后端响应的完整数据
    print(res.data);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          'Dio 插件',
          style: TextStyle(
            color: Colors.white,
          ),
        ),
        backgroundColor: Colors.purple,
      ),
    );
  }
}
